import 'package:flutter/cupertino.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';

import '../../http/api.dart';
import '../../language.dart';

class ChangePwdLogic extends GetxController {
  var oldPwd = "".obs;
  var newPwd = "".obs;
  var confirmPwd = "".obs;
  var isHidePwd1 = true.obs;
  var isHidePwd2 = true.obs;
  var isHidePwd3 = true.obs;
  FocusNode focusNode1 = FocusNode();
  FocusNode focusNode2 = FocusNode();
  FocusNode focusNode3 = FocusNode();


  upPwd() async {
    FocusManager.instance.primaryFocus?.unfocus();

    if (oldPwd.value.length<6) {
      EasyLoading.showToast(LanguageMsg.loginInputPwdTips.tr);
      return;
    }
    if (newPwd.value.length < 6) {
      EasyLoading.showToast(LanguageMsg.loginInputPwdTips.tr);
      return;
    }
    if (confirmPwd.value.length < 6) {
      EasyLoading.showToast(LanguageMsg.loginInputPwdTips.tr);
      return;
    }

    EasyLoading.show(status: 'loading...');
    dynamic result = await Api.updatePassword({
      'type':'1',
      'old_password': oldPwd.value,
      'new_password': newPwd.value,
      'confirm_password': confirmPwd.value,
    });
    EasyLoading.dismiss();
    if (result['code'] == 1) {
      EasyLoading.showSuccess('Password changed successfully!');
      Get.back(result: true);
    }
  }


  @override
  void onReady() {
    // TODO: implement onReady
    super.onReady();
  }

  @override
  void onClose() {
    // TODO: implement onClose
    FocusManager.instance.primaryFocus?.unfocus();
    super.onClose();
  }
}
